package com.lb.bs.client.zookeeper;

import com.lb.bs.client.annotation.SingletonMark;
import com.lb.bs.client.processor.beans.ProcessorBean;
import com.lb.bs.client.processor.beans.ProcessorDynamicBean;
import com.lb.bs.client.processor.enums.ProcessorType;
import com.lb.bs.client.processor.mgr.ProcessorMgr;
import com.lb.bs.client.repository.BeanHolder;
import com.lb.bs.client.repository.StoreCenter;
import com.lb.bs.client.util.GrayUtil;

import java.util.Collection;

/**
 * program: fianl
 * author: bsworld.xie
 * create: 2020-03-20 11:18
 * description:
 */
@SingletonMark
public class FetchMgr {

    /**
     * 对logPath进行更新并回调
     * <p>
     * 对非logPath的itemKey只更新但是不回调
     */
    public void reloadOneItem(String itemKey) {
        String data = ZKMgr.getInstance().getData(itemKey);
        //如果是log Path需要执行更新操作，这样可以处理回调
        ProcessorDynamicBean.Builder dynamicBuilder = ProcessorDynamicBean.builder().key(itemKey).data(data);
        dynamicBuilder.enableUpdateCallBack(GrayUtil.isLogPath(itemKey));
        ProcessorBean<ProcessorDynamicBean> processorBean = ProcessorBean.<ProcessorDynamicBean>builder()
                .data(dynamicBuilder.build())
                .processorType(ProcessorType.UPDATE)
                .async(true)
                .build();
        ProcessorMgr<ProcessorDynamicBean> processorMgr = BeanHolder.getHolder().getBean(ProcessorMgr.class);
        processorMgr.route(processorBean);
    }

    /**
     * 暂时不用
     */
    private void reloadAllItem() {

    }
}
